// This page implements tell a Colleague functionality 
// Author: Rupinder Saini
// dated: May 30, 2006

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using SiteManager;

public partial class Doctor_TellaColleague : System.Web.UI.Page
{
    // creating an instance of manager class
    Manager objmanager = new Manager(true,"ConnectionString");
    protected void Page_Load(object sender, EventArgs e)
    {
        
        localFunction lFunction = new localFunction();
        if (!IsPostBack)
        {
          //  if (Session["userType"].ToString() == "SiteUser")
           // {
             // check if doctor logged in
                if (!lFunction.checkDoctorLogin(false))
                {
                    Response.Redirect(Session["strHttp"] + "doctor/doctorLogin.aspx");
                }
                else
                {
                    lblName.Text = Session["LoginName"].ToString();
                    lblEmail.Text = Session["UserEmail"].ToString();
                    lbl_welcome.Text = "<b>Welcome</b>" + Session["LoginName"].ToString();
                    //mview.Visible = true;
                }
           // }
            //else
            //{
            //    // this.Visible = false;
            //}
        }
       
    }


    protected void btnSubmit_Click(object sender, ImageClickEventArgs e)
    {
          lblNoEmail.Visible = false;
        Validation IsValidate = new Validation();
        TextBox txtEMail;
        
        string strMessage = "";
        for (int i = 1; i <= 5; i++)
        {            
            txtEMail = (TextBox)view1.FindControl("txtEmail" + i);
            // check validations
            IsValidate.AddValidation(txtEMail.Text.Trim(), Validation.ValidationCommand.maxlen, "Email maximum length is only 50 characters for Colleague " + i, "50");
            IsValidate.AddValidation(txtEMail.Text.Trim(), Validation.ValidationCommand.email, "Please enter a valid email Id for Friend " + i + ".", "");
        }
        // show errors if any
        if (IsValidate.CheckError() == false)
        {
            errorlist.DataSource = IsValidate.ErrList;
            errorlist.DataBind();
        }
        else
        {
            // send the mail
            if (txtEmail1.Text.Trim().Length > 0 || txtEmail2.Text.Trim().Length > 0 || txtEmail3.Text.Trim().Length > 0 || txtEmail4.Text.Trim().Length > 0 || txtEmail5.Text.Trim().Length > 0)
            {
                strMessage = "Message Type : - " + ddlTypeMessage.SelectedItem.Text.ToString() + "<BR>" + txtMessage.Text;
                for (int i = 1; i <= 5; i++)
                {
                    txtEMail = (TextBox)view1.FindControl("txtEmail" + i);
                    if (txtEMail.Text != "")
                    {
                        objmanager.sendMail(strMessage, txtEMail.Text, Session["LoginName"].ToString(), txtSubject.Text, Session["UserEmail"].ToString(), "");
                       // objmanager.sendJMail(strMessage, txtEMail.Text, txtSubject.Text, Session["UserEmail"].ToString(), Session["LoginName"].ToString(), "");
                    }
                }
             //   mview.SetActiveView(view2);               
                view1.Visible = false;
                view2.Visible = true;
            }
            else // no email address specified
            {
                lblNoEmail.Text = "<FONT color=red>Please enter atleast one email Id .</FONT>";
                lblNoEmail.Visible = true;
            }
        }
    }
    }

